package com.sinoeyes.controller.flowdata;

import com.sinoeyes.common.core.controller.BaseController;
import com.sinoeyes.common.core.page.RestPageResult;
import com.sinoeyes.common.result.RCode;
import com.sinoeyes.common.result.Result;
import com.sinoeyes.common.utils.bean.ObjectUtils;
import com.sinoeyes.flowdata.filter.FlowStoreDataFilter;
import com.sinoeyes.flowdata.service.IFlowStoreDataService;
import com.sinoeyes.flowdata.vo.FlowStoreDatasVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 标准库存流向Controller
 * 
 * @author steven.zhang
 * @date 2019-10-10
 */
@Api(value = "FlowData Store API", tags = {"标准库存流向接口"})
@RestController
@RequestMapping("/flowdata/store")
public class IFlowStoreDatasController extends BaseController{

    @Autowired
    private IFlowStoreDataService flowStoreDatasService;

    @ResponseBody
    @ApiOperation("获取单条流向数据信息")
    @ApiImplicitParam(name = "id", value = "流向数据ID", required = true, dataType = "String", paramType = "path")
    @GetMapping("/getFlowStoreDataById/{id}")
    public Result<FlowStoreDatasVo> getDimensionInfoById(@PathVariable String id) {
        FlowStoreDatasVo flowStoreDatasVo = flowStoreDatasService.selectFlowStoreDatasById(id);
        if (ObjectUtils.isNotEmpty(flowStoreDatasVo)) {
            return Result.success(flowStoreDatasVo);
        }
        return Result.failure(RCode.NO_QUERY);
    }

    @ResponseBody
    @ApiOperation("获取流向数据列表")
    @PostMapping("/getFlowStoreDatasByFilter")
    public Result<RestPageResult<FlowStoreDatasVo>> getFlowStoreDatasByFilter(@RequestBody(required = false) FlowStoreDataFilter flowStoreDataFilter) {
        RestPageResult<FlowStoreDatasVo> pageResult = flowStoreDatasService.selectFlowStoreDatasByFilter(flowStoreDataFilter);
        if (pageResult != null) {
            return Result.success(pageResult);
        }
        return Result.failure(RCode.NO_QUERY);
    }
}
